﻿#include<iostream>
#include<memory>
using namespace std;

struct Date
{
	Date(int year = 0,int month = 0,int day = 0)
		:_day(day)
		,_month(month)
		,_year(year)
	{ }

	~Date()
	{
		cout << "~Date" << endl;
	}

	int _day;
	int _month;
	int _year;
};


int main()
{
	auto_ptr<Date> ap1(new Date);
	//拷贝时，拷贝对象安排ap1会被悬空
	auto_ptr<Date> ap2(ap1);
	//此时访问ap1就会报错
	//ap1->_day;


	unique_ptr<Date> up1(new Date);
	//不支持拷贝
	//unique_ptr<Date> up2(up1);
	// 
	//支持移动,但是移动后up1也被悬空
	unique_ptr<Date> up2(move(up1));


	shared_ptr<Date> sp1(new Date);
	//支持拷贝
	shared_ptr<Date> sp2(sp1);
	shared_ptr<Date> sp3(sp2);
	cout << sp1.use_count() << endl;
	cout << sp1->_year << endl;
	cout << sp2->_year << endl;
	cout << sp3->_year << endl;

	// ⽀持移动，但是移动后sp1也悬空，所以使用移动要谨慎 
	shared_ptr<Date> sp4(move(sp1));

}
